package leetcode.code2054;

import java.util.Arrays;
import java.util.PriorityQueue;

import leetcode.IDebug;

public class Solution implements IDebug {

	public int maxTwoEvents(int[][] events) {
		Arrays.sort(events, (a, b) -> a[0] - b[0]);
		int ans = 0;
		PriorityQueue<int[]> queue = new PriorityQueue<>((a, b) -> a[0] - b[0]);
		int max = 0;
		for (int i = 0; i < events.length; i++) {
			int[] e = events[i];
			int start = e[0], end = e[1], value = e[2];
			while (!queue.isEmpty() && queue.peek()[0] < start) {
				int[] cur = queue.poll();
				max = Math.max(max, cur[1]);
			}
			ans = Math.max(value + max, ans);
			queue.add(new int[] { end, value });
		}
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
